'use strict';

const { Controller } = require('egg');
const Result = require('../util/result');

class TrainController extends Controller {
  async index() {
    const query = {
      limit: Result.toInt(this.ctx.query.limit),
      offset: Result.toInt(this.ctx.query.offset),
    };
    const response = await this.ctx.service.train.index(query);
    this.ctx.body = response;
  }

  async create() {
    const data = this.ctx.request.body;
    const response = await this.ctx.service.train.create(data);
    this.ctx.body = response;
  }

  async show() {
    const id = this.ctx.params.id;
    const response = await this.ctx.service.train.show(id);
    this.ctx.body = response;
  }

  async update() {
    const id = this.ctx.params.id;
    const data = this.ctx.request.body;
    const response = await this.ctx.service.train.update(id, data);
    this.ctx.body = response;
  }

  async destroy() {
    const id = this.ctx.params.id;
    const response = await this.ctx.service.train.destroy(id);
    this.ctx.body = response;
  }
}

module.exports = TrainController;
